package com.hjxr.quota.sdoc.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.hjxr.common.core.controller.BaseController;
import com.hjxr.quota.sdoc.domain.SdocColname;
import com.hjxr.quota.sdoc.service.SdocColnameService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/column")
public class SdocColumnController extends BaseController {

    @Resource
    private SdocColnameService sdocColnameService;

    @GetMapping("/list/{docId}")
    public R<List<SdocColname>> getListByDocId(@PathVariable("docId") Integer docId) {
        List<SdocColname> result = sdocColnameService.getListByDocId(docId);
        return success(result);
    }


    /**
     * 修改数据
     *
     * @param sdocColname 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    @ApiOperation("修改数据")
    public R<Boolean> updateSdocColname(@RequestBody SdocColname sdocColname){
        int result = sdocColnameService.updateSdocCloname(sdocColname);
        R<Boolean> r = success(result > 0);
        return r;
    }

    /**
     * 删除数据
     *
     * @param ids 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除数据")
    public R<Boolean> delete(@RequestParam("idList")  List<Integer> ids) {
        return success(this.sdocColnameService.removeByIds(ids));
    }
    /**
     * 查询数据
     * @param id 主键
     * @return 删除结果
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    public R<SdocColname> query(@PathVariable Serializable id){
        return success(this.sdocColnameService.getById(id));
    }
}
